package com.lanou.moving.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.moving.fragment.MVClassifyFragment;
import com.lanou.moving.fragment.MVDaylyFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 梁树珍 on 15/11/3.
 */
public class MVAreaAdapter extends FragmentPagerAdapter{
    private List<Fragment> fragments;
    private String[] titles = {"每日一发", "MV分类"};
    private FragmentManager fm;
    public MVAreaAdapter(FragmentManager fm) {
        super(fm);
        this.fm = fm;
        init();
    }

    private void init(){
        fragments = new ArrayList<>();
        fragments.add(new MVDaylyFragment());
        fragments.add(new MVClassifyFragment());
    }
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    public void killAllFragments(){
        for(int i= 0;i<fragments.size();i++){
            fm.beginTransaction().remove(fragments.get(i)).commit();
        }
    }
}
